home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
C64
/
G-Games
/
(c)gb.d64
/
connect 4.c
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2007-02-04
|
2KB
|
99 lines
100 REM ****** CONNECT 4 ********
130 DIMB(8,7),E(2,9),Y(3),X(3)
200 GOSUB8000
220 IFNP=1ANDRND(0)>.5THENPRINT" I'LL GO FIRST THIS TIME":GOTO300
250 C=2:GOSUB7000
300 C=1
310 IFNP=2THENGOSUB7000:GOTO250
350 GOSUB1000:GOTO250
499 REM * EVAL X & Y
500 E=EC(X)
510 FORD=0TO3
520 Q=X(D):R=Y(D)
530 FORC1=1TO2
540 N=0:I=X+Q:J=Y+R
550 IFB(I,J)<>C1THEN580
560 I=I+Q:J=J+R:N=N+1
570 IFB(I,J)=C1THEN560
580 O=(B(I,J)=0)
590 I=X-Q:J=Y-R
600 IFB(I,J)<>C1THEN630
610 I=I-Q:J=J-R:N=N+1
620 IFB(I,J)=C1THEN610
630 O=-(B(I,J)=0)-O
640 A=N*3+O:IFA>9THENA=9
645 C2=C1:IFC=2THENC2=3-C2
650 E=E+E(C2,A)
660 NEXT
670 NEXT
890 RETURN
996 /22
1000 REM ***** COMP MOVE ********
1020 B=-1:BE=-1E9
1050 FORX=1TO7
1060 GOSUB1900:IFY>6THEN1200
1100 GOSUB500
1110 PRINT""TAB(X*3+5)MID$(STR$(E),2)
1120 IFE>BETHENBE=E:B=X
1200 NEXTX
1400 X=B:IFX<0THENRETURN
1410 GOSUB7500
1420 IFE<500THENRETURN
1430 PRINT"[159] I WIN. HIT SPACE "
1440 GETA$:IFA$<>" "THEN1440
1450 RUN
1900 FORY=1TO6:IFB(X,Y)THENNEXT
1910 RETURN
7000 GOSUB7400
7020 PRINT" "MID$("WHITEBLACK",C*5-4,5)" MOVE (OR STOP) "
7030 GETA$:IFA$<>""THEN7030
7050 GETA$:IFA$="S"THENRUN
7100 X=VAL(A$)
7110 IFX=0ORX>7THEN7050
7120 GOSUB7500
7150 IFY>6THEN7050
7200 IFE<500THEN7400
7210 PRINT" YOU WIN. HIT SPACE "
7250 GETA$:IFA$<>" "THEN7250
7270 RUN
7400 FORA=1104TO1223:POKEA,32
7410 NEXT
7490 RETURN
7500 FORY=1TO6
7510 IFB(X,Y)THENNEXT:RETURN
7550 FORA=X*3+1189TOX*3+2009-Y*120STEP40
7555 POKEA-40,32:POKEA-39,32
7560 IFC=1THENPOKEA,233:POKEA+1,223:POKEA+40,95:POKEA+41,105
7570 IFC=2THENPOKEA,78:POKEA+1,77:POKEA+40,77:POKEA+41,78
7600 NEXTA
7610 GOSUB500
7650 B(X,Y)=C
7990 RETURN
8000 REM ******* NEW GAME **********
8010 PRINT"[147][158] *** CONNECT 4 *** "
8020 PRINT" 1 OR 2 PLAYERS ? "
8025 POKE53281,0:POKE53280,10
8050 PRINT""
8100 FORX=1TO18:PRINT" [221] [221] [221] [221] [221] [221] [221] [221]":NEXT
8120 PRINT" 1 2 3 4 5 6 7 "
8130 GETA$:NP=VAL(A$)
8140 IFNP<1ORNP>2THEN8130
8200 FORX=1TO7:FORY=1TO6
8205 B(X,Y)=0:NEXT:NEXT
8210 FORX=0TO8:B(X,0)=-1
8215 B(X,7)=-1:NEXT
8220 FORY=0TO7:B(0,Y)=-1
8225 B(8,Y)=-1:NEXT
8400 RESTORE
8410 FORC=1TO2:FORX=0TO9
8415 READE(C,X):NEXT:NEXT
8420 FORX=0TO3:READX(X):NEXT
8430 FORX=0TO3:READY(X):NEXT
8450 FORX=1TO7:READEC(X):NEXT
8490 RETURN
9600 DATA0,2,3,0,4,6,1,12,16,1000
9620 DATA0,0,0,0,2,3,0,8,11,120
9700 DATA0,1,1,1
9710 DATA1,1,0,-1
9750 DATA0,0,1,3,1,0,0